import request from '@/axios'

export interface SysDict {
  dictId?: number | string
  dictParentId?: number | string
  dictTypeCode: string
  dictCode: string
  dictName: string
  ordinal?: number
  remark?: string
  createUserId?: number | string
  createUserName?: string
  createTime?: string
  updateUserId?: number | string
  updateUserName?: string
  updateTime?: string
}

export interface DictDTO {
  dictId?: number | string
  dictParentId?: number | string
  dictTypeCode: string
  dictCode: string
  dictName: string
  ordinal?: number
  remark?: string
  children?: DictDTO[]
}

export interface SysDictType {
  dictTypeId?: number | string
  dictTypeCode: string
  dictTypeName: string
  createUserId?: number | string
  createUserName?: string
  createTime?: string
  updateUserId?: number | string
  updateUserName?: string
  updateTime?: string
}

// 获取字典树
export const getSysDictListApi = (params?: { dictTypeCode?: string; dictTypeId?: number }) => {
  return request.get({ url: '/api/system/dict/listDictTree', params })
}

// 根据类型获取字典列表
export const getSysDictByTypeApi = (dictTypeCode: string) => {
  return request.get({ url: `/api/system/dict/getByType`, params: { dictTypeCode } })
}

// 获取字典详情
export const getSysDictDetailApi = (id: number | string) => {
  return request.get({ url: `/api/system/dict/get`, params: { dictId: id } })
}

// 新增或更新字典
export const saveOrUpdateSysDictApi = (data: SysDict) => {
  return request.post({ url: '/api/system/dict/saveOrUpdate', data })
}

// 删除字典
export const deleteSysDictApi = (id: number | string) => {
  return request.get({ url: '/api/system/dict/delete', params: { dictId: id } })
}

// 获取字典类型列表
export const getSysDictTypeListApi = () => {
  return request.get({ url: '/api/system/dict-type/list' })
}

// 获取字典类型详情
export const getSysDictTypeDetailApi = (id: number | string) => {
  return request.get({ url: `/api/system/dict-type/get`, params: { dictTypeId: id } })
}

// 新增或更新字典类型
export const saveOrUpdateSysDictTypeApi = (data: SysDictType) => {
  return request.post({ url: '/api/system/dict-type/saveOrUpdate', data })
}

// 删除字典类型
export const deleteSysDictTypeApi = (id: number | string) => {
  return request.get({ url: '/api/system/dict-type/delete', params: { dictTypeId: id } })
}
